﻿using Framework.Core.Consts;
using Mapster;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using my.abp.Application.Contracts.Dtos.Menu;
using my.abp.Application.Contracts.IServices.Menu;
using my.abp.Domain.IManagers.Menu;
using my.abp.Domain.Shared.Entities;
using my.abp.Domain.Shared.Enums;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Uow;

namespace my.abp.Application.Services.Menu
{
	public class SysMenuService: ApplicationService, ISysMenuService
	{
		private readonly ISysMenuManager _sysMenuManager;
		public SysMenuService(ISysMenuManager sysMenuManager) 
		{
			_sysMenuManager = sysMenuManager;
		}

		/// <summary>
		/// 获取登录菜单树
		/// </summary>
		/// <returns></returns>
		[Authorize]
		[DisplayName("获取登录菜单树")]
		public async Task<List<MenuOutput>> GetLoginMenuTree()
		{
			var menuList = await _sysMenuManager.GetLoginMenuTree();
			return menuList.Adapt<List<MenuOutput>>();
		}

		/// <summary>
		/// 获取菜单列表
		/// </summary>
		/// <returns></returns>
		[Authorize]
		[DisplayName("获取菜单列表")]
		public async Task<List<SysMenu>> GetList([FromQuery] MenuInput input)
		{
			return await _sysMenuManager.GetList(input.Adapt<SysMenu>());
		}

		/// <summary>
		/// 增加菜单
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[HttpPost]
		[DisplayName("增加菜单")]
		public async Task AddMenu(AddMenuInput input)
		{
			await _sysMenuManager.AddMenu(input.Adapt<SysMenu>());
		}

		/// <summary>
		/// 更新菜单
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[HttpPost]
		[DisplayName("更新菜单")]
		public async Task UpdateMenu(UpdateMenuInput input)
		{
			await _sysMenuManager.UpdateMenu(input.Adapt<SysMenu>());
		}

		/// <summary>
		/// 删除菜单
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[HttpPost]
		[DisplayName("删除菜单")]
		public async Task DeleteMenu(DeleteMenuInput input)
		{
			await _sysMenuManager.DeleteMenu(input.Adapt<SysMenu>());
		}

		/// <summary>
		/// 获取用户拥有按钮权限集合（缓存）
		/// </summary>
		/// <returns></returns>
		[DisplayName("获取按钮权限集合")]
		public async Task<List<string>> GetOwnBtnPermList()
		{
			return await _sysMenuManager.GetOwnBtnPermList();
		}
	}
}
